package response

import (
	"go.getaway.adminspro.padmins.com/untils/di"
)

type Message struct {
	Msg     string      `json:"msg"`
	Code    int         `json:"code"`
	Desc    string      `json:"desc"`
	Data    interface{} `json:"data"`
	Runtime string      `json:"runtime"`
}

type Response struct {
	Message
	Di *di.Di
}

func (r *Response) Success(data interface{}, params ...interface{}) *Message {
	m := &Message{}
	m.Msg = "success"
	m.Desc = "请求成功"
	m.Code = 0
	m.Data = data
	switch len(params) {
	case 1:
		m.Desc = params[0].(string)
		break
	case 2:
		m.Desc = params[0].(string)
		m.Code = params[1].(int)
		break
	}

	return m
}

func (r *Response) Error(code int, params ...interface{}) *Message {
	m := &Message{
		Msg:     "error",
		Code:    code,
		Desc:    "请求失败",
		Data:    []byte{},
		Runtime: "",
	}
	switch len(params) {
	case 1:
		m.Msg = params[0].(string)
		break
	case 2:
		m.Msg = params[0].(string)
		m.Desc = params[1].(string)
		break
	}

	return m
}
